package com.goodomen.garbage.common.utils;

import com.csvreader.CsvReader;
import com.csvreader.CsvWriter;

import java.io.*;

/**
 * @author : Zhao Da
 * @since : 2019/10/10 10:12
 */
public class Tool {


    public static void main(String[] args) {
		File file = new File("D://passport.csv");


		String inString = "";
		String tmpString = "";
		File inFile = new File("D://passport.csv"); // 读取的CSV文件
		File outFile = new File("D://outtest.csv");//输出的CSV文
		try {
			DataInputStream in = new DataInputStream(new FileInputStream(new File("D://passport.csv")));
			BufferedReader reader = new BufferedReader(new InputStreamReader(in,"utf8"));

			DataOutputStream out = new DataOutputStream(new FileOutputStream(new File("D://outtest.csv")));
			BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out,"gbk"));

//			BufferedReader reader = new BufferedReader(new FileReader(inFile));
//			BufferedWriter writer = new BufferedWriter(new FileWriter(outFile));
			CsvReader creader = new CsvReader(reader, ',');
			CsvWriter cwriter = new CsvWriter(writer,',');

			creader.readRecord();
			while(creader.readRecord()){
				inString = creader.getRawRecord();//读取一行数据
				inString = inString.replaceAll("\"", "");
				String [] inStrings = inString.split(",");
				String mobileAes = inStrings[2];
				inStrings[2] = AESEncrypter.getDecrypt(mobileAes, "#w$a341#23%2d@13fashjytknms#@456$@swfd");
				//第一个参数表示要写入的字符串数组，每一个元素占一个单元格，第二个参数为true时表示写完数据后自动换行
				cwriter.writeRecord(inStrings, true);
				cwriter.flush();//刷新数据
			}
			creader.close();
			cwriter.close();
		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		/*String tmpString = "";
		File outFile = new File("D://outtest.csv");//输出的CSV文
		try {
			DataOutputStream out = new DataOutputStream(new FileOutputStream(new File("D://outtest.csv")));
			BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out,"gbk"));
			CsvWriter cwriter = new CsvWriter(writer,',');
			List<String> x = new ArrayList<>();
			x.add("1,2,3,4,5");
			x.add("2,3,4,5,6");
			for (String y : x) {
				//读取一行数据
				String inString = y;
				String [] inStrings = inString.split(",");
				//第一个参数表示要写入的字符串数组，每一个元素占一个单元格，第二个参数为true时表示写完数据后自动换行
				cwriter.writeRecord(inStrings, true);
				//刷新数据
				cwriter.flush();
			}
			cwriter.close();
		} catch (FileNotFoundException ex) {
			ex.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}*/

//        System.out.println(AESEncrypter.getEncrypt("18689613928", "#w$a341#23%2d@13fashjytknms#@456$@swfd"));
//		System.out.println(AESEncrypter.getDecrypt("6e277dd31ac8339197b3a72474cb954e722e5f932840601088dd3044096beb6f", "#w$a341#23%2d@13fashjytknms#@456$@swfd"));


//				System.out.println(com.sangame.passport.utils.AESEncrypter.getEncrypt("12344444444", "test"));
//		System.out.println(AESEncrypter.getDecrypt("d13e6f73863a1c81898227da1563713a722e5f932840601088dd3044096beb6f", "test"));
    }
}
